package com.d3works.apps.base.service.app;

import com.d3works.apps.base.db.App;
import com.d3works.apps.base.exceptions.AdminExceptionMessage;
import com.d3works.db.Model;
import com.d3works.exception.D3worksException;
import com.d3works.exception.db.repo.TraceBackRepository;
import com.d3works.i18n.I18n;
import com.d3works.meta.MetaFiles;
import java.io.File;
import java.io.IOException;
import java.util.Collection;

public interface AppService {

  public App importDataDemo(App app) throws D3worksException, IOException;

  public Model getApp(String type);

  public boolean isApp(String type);

  public App installApp(App app, String language) throws D3worksException, IOException;

  public App unInstallApp(App app) throws D3worksException;

  public void refreshApp() throws IOException, ClassNotFoundException;

  public void bulkInstall(Collection<App> apps, Boolean importDeomo, String language)
      throws D3worksException, IOException;

  public App importRoles(App app) throws D3worksException, IOException;

  public void importRoles() throws D3worksException, IOException;

  public String getDataExportDir() throws D3worksException;

  public static String getFileUploadDir() throws D3worksException {
    String appSettingsPath = MetaFiles.getPath("tmp").getParent().toString();
    if (appSettingsPath == null || appSettingsPath.isEmpty()) {
      throw new D3worksException(
          TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
          I18n.get(AdminExceptionMessage.FILE_UPLOAD_DIR_ERROR));
    }
    return !appSettingsPath.endsWith(File.separator)
        ? appSettingsPath + File.separator
        : appSettingsPath;
  }
}
